home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / misc / amag / 12b92.lha / Tips & Tricks / Form. Strings (Assembler) / Format_Demo.asm < prev    next >
Assembly Source File  |  1992-11-02  |  3KB  |  92 lines

  1. * * Name     : FormatBsp.asm
  2. * * Autor    : Frank Enderle
  3. * *
  4. * * Assembler: A68K  (Fish 521)
  5. * * Linker   : Blink (Fish 351)
  6.  
  7. RawDoFmt       EQU     -522
  8. OpenLibrary    EQU     -552
  9. CloseLibrary   EQU     -414
  10. Write          EQU     -48
  11. Output         EQU     -60
  12. ExecBase       EQU     $4
  13.  
  14. Start:    move.l  ExecBase,a6
  15.           lea     DosName,a1
  16.           moveq   #0,d0
  17.           jsr     OpenLibrary(a6) ; Dos öffnen
  18.           tst.l   d0
  19.           beq     1$
  20.           move.l  d0,DosBase
  21.  
  22. * Handle besorgen
  23.           move.l  DosBase,a6
  24.           jsr     Output(a6)
  25.           move.l  d0,Handle
  26.  
  27. * Argumente
  28.           move.w  #-1562,-(a7)       ;    2 Bytes (WORD)
  29.           move.w  #1625,-(a7)        ;    2 Bytes (WORD)
  30.           move.w  #'Z',-(a7)         ;    2 Bytes (WORD)
  31.           pea     String             ;    4 Bytes (LONG)
  32.           move.l  #$98CAF2,-(a7)     ; +  4 Bytes (LONG)
  33.           move.l  a7,a2              ; -----------------
  34.                                      ;   14 Bytes
  35.           lea     Format,a1          ; Formatstring
  36.           lea     Buffer,a0          ; Puffer
  37.           bsr     FormatStr          ; String formatieren
  38.           lea     14(a7),a7          ; Stack um 14 Bytes                                     ; korrigieren
  39.           lea     Buffer,a0
  40.           bsr     Print              ; String ausgeben
  41.           move.l  DosBase,a1
  42.           move.l  ExecBase,a6
  43.           jsr     CloseLibrary(a6)   ; Dos schließen
  44. 1$:       rts
  45. ;------------------------------------------------------------
  46. ; Print gibt einen String der in a0 übergeben wird im
  47. ; Output Handle aus. Der String muß mit einem NULL Byte enden
  48.  
  49. Print:          movem.l d0-d7/a0-a6,-(a7)
  50.                 move.l  Handle,d1
  51.                 move.l  a0,d2
  52.                 clr.l   d3
  53. 1$:             tst.b   (a0)+
  54.                 beq     2$
  55.                 addq.l  #1,d3
  56.                 bra     1$
  57. 2$:             move.l  DosBase,a6
  58.                 jsr     Write(a6)
  59.                 movem.l (a7)+,a0-a6/d0-d7
  60.                 rts
  61. ;------------------------------------------------------------
  62. ; Format formatiert einen String wie es in C üblich ist
  63. ; (mit ein paar wenigen Ausnahmen)
  64. ; a0   -> Zeiger auf einen Puffer der den komplett
  65. ; formatierten String aufnehmen kann.
  66. ; a1   -> Zeiger auf den zu formatierenden String.
  67. ; a2   -> Zeiger auf eine Liste von Argumenten
  68.  
  69. FormatStr:      movem.l d0-d7/a0-a6,-(a7)
  70.                 move.l  a0,a3
  71.                 move.l  a1,a0
  72.                 move.l  a2,a1
  73.                 move.l  #Routine,a2
  74.                 move.l  ExecBase,a6
  75.                 jsr     RawDoFmt(a6)
  76.                 movem.l (a7)+,d0-d7/a0-a6
  77.                 rts
  78. Routine:        move.b  d0,(a3)+
  79.                 rts
  80. ;----------------------------------------------------------
  81. DosName:        dc.b    "dos.library",0
  82. String:         dc.b    "Das ist ein Beispiel Text",0
  83. Format:         dc.b    "Eine 32 Bit Hex Zahl: %08lx",10
  84.                 dc.b    "Ein String          : %s",10
  85.                 dc.b    "Ein Buchstabe       : %c",10
  86.                 dc.b    "Eine 16 Bit Hex Zahl: %x",10
  87.                 dc.b    "Eine 16 Bit Dez Zahl: %d",10,0
  88. Buffer:         ds.b    300
  89. DosBase:        dc.l    0
  90. Handle:         dc.l    0
  91.                 END
  92.